package com.linewell.mobile.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import com.linewell.commom.dao.impl.BaseDaoImpl;
import com.linewell.mobile.model.User;


/**
 * 前端基础控制器 放置一些公共的方法和成员变量，供后台别的控制器调用，减少代码量
 */
@Controller
@EnableWebMvc
public class MobileBaseController extends BaseDaoImpl {
	private static final Log log = LogFactory.getLog(MobileBaseController.class);
	public String basePath = "" + ContextLoader.getCurrentWebApplicationContext();

	/**
	 * 由于底部栏不变，将其代码放在统一地方，便于管理
	 * 
	 */
	public String index(String view_list, HttpServletRequest request) {

		StringBuffer bottombase = new StringBuffer();
		bottombase.append("<div data-am-widget=\"navbar\" class=\"am-navbar am-cf am-navbar-default gm-foot\"   id=\"\">");
		bottombase.append("<ul class=\"am-navbar-nav am-cf am-avg-sm-4\">");
		bottombase.append(
				"<li ><a href=\"/mobile/\" target=\"_self\" class=\"curr\"> <span class=\"am-icon-home\"></span> <span class=\"am-navbar-label\">首页</span> </a></li>");
		bottombase.append(
				"<li> <a href=\"/mobile/market\" target=\"_self\"  class=\"curr\"> <span class=\"am-icon-list\"></span> <span class=\"am-navbar-label\">二手市场</span> </a> </li>");
		bottombase.append(
				"<li > <a href=\"/manage/feedBack/add\" target=\"_self\" class=\"curr\"> <span class=\"am-icon-location-arrow\"></span> <span class=\"am-navbar-label\">留言板</span> </a> </li>");
		bottombase.append(
				"<li > <a href=\"/mobile/gomy\" target=\"_self\" class=\"curr\"> <span class=\"am-icon-user\"></span> <span class=\"am-navbar-label\">我的</span> </a> </li>");
		bottombase.append("</ul> </div>");
		request.setAttribute("bottom", bottombase.toString());
		return view_list;

	}
	/**
	 * 获取当前用户的openId
	 * 
	 * @return
	 */

	public static String getUserOpenId(HttpServletRequest request) {

		HttpSession session = request.getSession();
		if (session.getAttribute("customer") != null && session.getAttribute("customer") != "") {
			User obj = (User) session.getAttribute("customer");
			return obj.getOpenId();
		}
		return null;

	}
	/**
	 * 获取当前用户的userName,用户识别当前用户是否填写了完整资料
	 * 
	 * @return
	 */

	public static String getUserName(HttpServletRequest request) {
		HttpSession session = request.getSession();
		if (session.getAttribute("customer") != null && session.getAttribute("customer") != "") {
			User obj = (User) session.getAttribute("customer");
			return obj.getUserName();
		}
		return null;

	}

	/**
	 * 获取当前用户的地理位置
	 * 
	 * @return
	 */

	public static String getLocation(HttpServletRequest request) {

		HttpSession session = request.getSession();
		if (session.getAttribute("customer") != null && session.getAttribute("customer") != "") {
			User obj = (User) session.getAttribute("customer");
			return obj.getLocation();
		}
		return null;

	}

}
